FROM ubuntu:20.04

ARG ARCH
ARG GAUSSHOME=/usr/local/uqbar

WORKDIR /warehouse

RUN set -eux; \
    if [ "$ARCH" = "arm64" ]; then \
        echo "deb http://mirror.tuna.tsinghua.edu.cn/ubuntu-ports/ focal main restricted universe multiverse" >/etc/apt/sources.list && \
        echo "deb http://mirror.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse" >>/etc/apt/sources.list && \
        echo "deb http://mirror.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse" >>/etc/apt/sources.list && \
        echo "deb http://mirror.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-security main restricted universe multiverse" >>/etc/apt/sources.list && \
        echo "deb http://mirror.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-proposed main restricted universe multiverse" >>/etc/apt/sources.list; \
    elif [ "$ARCH" = "amd64" ]; then \
        echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse" >/etc/apt/sources.list && \
        echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse" >>/etc/apt/sources.list && \
        echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse" >>/etc/apt/sources.list && \
        echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse" >>/etc/apt/sources.list; \
    fi && \
    apt-get update && apt-get install -y \
    wget \
    make && \
    if [ "$ARCH" = "arm64" ]; then \
      wget https://gitee.com/lee1002/gosu/attach_files/944222/download/gosu-arm64 -O gosu; \
      wget https://cdn-mogdb.enmotech.com/uqbar/1.1.0/Uqbar-1.1.0-openEuler-arm64.tar.gz -O uqbar.tar.gz; \
    elif [ "$ARCH" = "amd64" ]; then \
      wget https://gitee.com/lee1002/gosu/attach_files/943635/download/gosu-amd64 -O gosu; \
      wget https://cdn-mogdb.enmotech.com/uqbar/1.1.0/Uqbar-1.1.0-openEuler-x86_64.tar.gz -O uqbar.tar.gz; \
    fi && \
    wget https://gitee.com/enmotech/compat-tools/attach_files/1110114/download/compat-tools-v2022.06.28.tar -O compat-tools-v2022.06.28.tar && \
    wget https://gitee.com/enmotech/mogila/attach_files/954052/download/mogila-v1.0.0.bz2 -O mogila-v1.0.0.bz2 && \
    mkdir -p $GAUSSHOME && \
    tar xf uqbar.tar.gz  && tar xf Uqbar-1.1.0-openEuler-64bit.tar.gz -C $GAUSSHOME && \
    rm -f uqbar.tar.gz && \
    chmod 755 gosu && \
    tar xf compat-tools-v2022.06.28.tar && mv compat-tools-v2022.06.28 compat-tools && \
    tar xf mogila-v1.0.0.bz2